Read and preprocess control-data

if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(tidyverse)
p_load(R.utils)
sourceDirectory("./source/")
data<-readControl()  %>% preproControl() 

check accuracy

corrResp: correct response rtResp: reaction time of response - inSet: 0 - correct rejection (true negativ) - inSet: 1 - Hit (true positiv) - session: 1-5 - time factor (not constant, therefore only ordinal) - kategory: Landscape, Face, Art

p_load(dplyr)
p_load(brms)
options (mc.cores=parallel::detectCores ()) # Run on multiple cores
p_load(sjPlot)


group_by(data,kategory,session) %>% 
  summarize(mean_corr= mean(corrResp),sd_corr=sd(corrResp),mean_RT=mean(rtResp),sd_RT=sd(rtResp))
p <- ggplot(data=data, 
             aes(x = corrResp, y =rtResp, color= inSet) )+geom_point()
p+facet_grid(kategory  ~  session,margins = T)

p+facet_grid(kategory ~ participant)

#correct response 
fit_corrRespSession<-lm(corrResp~session*kategory,data = data)
summary(fit_corrRespSession)
## 
## Call:
## lm(formula = corrResp ~ session * kategory, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -0.90  -0.50   0.20   0.35   0.60 
## 
## Coefficients:
##                              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 5.000e-01  1.090e-01   4.588 8.83e-06 ***
## session2                    2.000e-01  1.888e-01   1.059    0.291    
## session3                    9.043e-16  1.888e-01   0.000    1.000    
## session4                    2.633e-16  1.888e-01   0.000    1.000    
## session5                   -1.000e-01  1.888e-01  -0.530    0.597    
## kategoryFace                1.500e-01  1.541e-01   0.973    0.332    
## kategoryLandscape           1.500e-01  1.541e-01   0.973    0.332    
## session2:kategoryFace      -1.500e-01  2.670e-01  -0.562    0.575    
## session3:kategoryFace       1.500e-01  2.670e-01   0.562    0.575    
## session4:kategoryFace       5.000e-02  2.670e-01   0.187    0.852    
## session5:kategoryFace       3.500e-01  2.670e-01   1.311    0.192    
## session2:kategoryLandscape -2.500e-01  2.670e-01  -0.936    0.350    
## session3:kategoryLandscape  1.500e-01  2.670e-01   0.562    0.575    
## session4:kategoryLandscape -5.000e-02  2.670e-01  -0.187    0.852    
## session5:kategoryLandscape -5.000e-02  2.670e-01  -0.187    0.852    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4874 on 165 degrees of freedom
## Multiple R-squared:  0.06802,    Adjusted R-squared:  -0.01105 
## F-statistic: 0.8602 on 14 and 165 DF,  p-value: 0.603
sjp.lm(fit = fit_corrRespSession)

fit_corrRespSet<-lm(corrResp~kategory*inSet,data = data)
summary(fit_corrRespSet)
## 
## Call:
## lm(formula = corrResp ~ kategory * inSet, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.93333 -0.10000  0.06667  0.20000  0.90000 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               0.93333    0.07267  12.843  < 2e-16 ***
## kategoryFace             -0.13333    0.10277  -1.297    0.196    
## kategoryLandscape        -0.50000    0.10277  -4.865 2.55e-06 ***
## inSet1                   -0.83333    0.10277  -8.109 8.80e-14 ***
## kategoryFace:inSet1       0.70000    0.14534   4.816 3.17e-06 ***
## kategoryLandscape:inSet1  1.23333    0.14534   8.486 9.06e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.398 on 174 degrees of freedom
## Multiple R-squared:  0.3446, Adjusted R-squared:  0.3258 
## F-statistic:  18.3 on 5 and 174 DF,  p-value: 1.415e-14
sjp.int(fit = fit_corrRespSet, type = "eff")

fit_corrRespParticipant<-lm(corrResp~kategory*participant,data = data)
summary(fit_corrRespParticipant)
## 
## Call:
## lm(formula = corrResp ~ kategory * participant, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -0.78  -0.50   0.22   0.34   0.50 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                         0.6000     0.1510   3.972 0.000104 ***
## kategoryFace                       -0.1000     0.2136  -0.468 0.640279    
## kategoryLandscape                  -0.1000     0.2136  -0.468 0.640279    
## participantug93                    -0.1000     0.1655  -0.604 0.546398    
## kategoryFace:participantug93        0.3800     0.2340   1.624 0.106209    
## kategoryLandscape:participantug93   0.2600     0.2340   1.111 0.268065    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4777 on 174 degrees of freedom
## Multiple R-squared:  0.05614,    Adjusted R-squared:  0.02901 
## F-statistic:  2.07 on 5 and 174 DF,  p-value: 0.07141
sjp.int(fit = fit_corrRespParticipant, type = "eff")

# reaction time
fit_rtResp<-lm(rtResp~kategory*inSet, data)
summary(fit_rtResp)
## 
## Call:
## lm(formula = rtResp ~ kategory * inSet, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8132 -0.4043 -0.1457  0.3317  2.6404 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               1.16506    0.10856  10.732   <2e-16 ***
## kategoryFace             -0.20441    0.15353  -1.331    0.185    
## kategoryLandscape         0.03700    0.15353   0.241    0.810    
## inSet1                   -0.06813    0.15353  -0.444    0.658    
## kategoryFace:inSet1       0.01956    0.21712   0.090    0.928    
## kategoryLandscape:inSet1 -0.34753    0.21712  -1.601    0.111    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5946 on 174 degrees of freedom
## Multiple R-squared:  0.05955,    Adjusted R-squared:  0.03252 
## F-statistic: 2.203 on 5 and 174 DF,  p-value: 0.05605
sjp.int(fit = fit_rtResp,type = "eff")

fit_rtRespSession<-lm(rtResp~kategory*session, data)
summary(fit_rtRespSession)
## 
## Call:
## lm(formula = rtResp ~ kategory * session, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.9656 -0.3469 -0.1126  0.2249  2.5806 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 1.18677    0.12971   9.149   <2e-16 ***
## kategoryFace               -0.21495    0.18344  -1.172   0.2430    
## kategoryLandscape          -0.44019    0.18344  -2.400   0.0175 *  
## session2                    0.38131    0.22467   1.697   0.0915 .  
## session3                   -0.29029    0.22467  -1.292   0.1981    
## session4                   -0.37214    0.22467  -1.656   0.0995 .  
## session5                   -0.05353    0.22467  -0.238   0.8120    
## kategoryFace:session2      -0.32967    0.31773  -1.038   0.3010    
## kategoryLandscape:session2 -0.15484    0.31773  -0.487   0.6267    
## kategoryFace:session3       0.04646    0.31773   0.146   0.8839    
## kategoryLandscape:session3  0.59178    0.31773   1.863   0.0643 .  
## kategoryFace:session4       0.16379    0.31773   0.515   0.6069    
## kategoryLandscape:session4  0.57675    0.31773   1.815   0.0713 .  
## kategoryFace:session5       0.24132    0.31773   0.760   0.4486    
## kategoryLandscape:session5  0.80687    0.31773   2.539   0.0120 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5801 on 165 degrees of freedom
## Multiple R-squared:  0.1512, Adjusted R-squared:  0.07918 
## F-statistic: 2.099 on 14 and 165 DF,  p-value: 0.01418
sjp.int(fit = fit_rtRespSession,type = "eff")
## `sjp.int()` will become deprecated in the future. Please use `plot_model()` instead.

fit_rtRespParticipant<-lm(rtResp~kategory*participant, data)
summary(fit_rtRespParticipant)
## 
## Call:
## lm(formula = rtResp ~ kategory * participant, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7837 -0.4254 -0.1708  0.3078  2.5689 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                         1.2803     0.1907   6.715 2.57e-10 ***
## kategoryFace                       -0.2968     0.2697  -1.101   0.2726    
## kategoryLandscape                  -0.5202     0.2697  -1.929   0.0553 .  
## participantug93                    -0.1792     0.2089  -0.858   0.3921    
## kategoryFace:participantug93        0.1226     0.2954   0.415   0.6787    
## kategoryLandscape:participantug93   0.4601     0.2954   1.558   0.1211    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.603 on 174 degrees of freedom
## Multiple R-squared:  0.03288,    Adjusted R-squared:  0.005087 
## F-statistic: 1.183 on 5 and 174 DF,  p-value: 0.3194
sjp.int(fit = fit_rtRespParticipant,type = "eff")

fitBrmCorrResp<-brm(corrResp~inSet*kategory+(1|session)+(1|participant)+(1|id),data = data,family = bernoulli())
## Compiling the C++ model
## Start sampling
summary(fitBrmCorrResp)
##  Family: bernoulli 
##   Links: mu = logit 
## Formula: corrResp ~ inSet * kategory + (1 | session) + (1 | participant) + (1 | id) 
##    Data: data (Number of observations: 180) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1; 
##          total post-warmup samples = 4000
##     ICs: LOO = NA; WAIC = NA; R2 = NA
##  
## Group-Level Effects: 
## ~id (Number of levels: 90) 
##               Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
## sd(Intercept)     0.84      0.64     0.04     2.45        247 1.02
## 
## ~participant (Number of levels: 2) 
##               Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
## sd(Intercept)     2.51      2.34     0.07     8.39         87 1.05
## 
## ~session (Number of levels: 5) 
##               Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
## sd(Intercept)     0.40      0.42     0.01     1.49       1449 1.00
## 
## Population-Level Effects: 
##                          Estimate Est.Error l-95% CI u-95% CI Eff.Sample
## Intercept                    2.81      2.09    -1.79     6.95         39
## inSet1                      -5.86      1.44    -9.25    -3.59        240
## kategoryFace                -1.62      1.03    -3.81     0.32        800
## kategoryLandscape           -3.63      1.11    -6.27    -1.87        331
## inSet1:kategoryFace          4.97      1.53     2.24     8.33        559
## inSet1:kategoryLandscape     8.13      1.81     5.32    12.51        240
##                          Rhat
## Intercept                1.11
## inSet1                   1.02
## kategoryFace             1.01
## kategoryLandscape        1.01
## inSet1:kategoryFace      1.01
## inSet1:kategoryLandscape 1.02
## 
## Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample 
## is a crude measure of effective sample size, and Rhat is the potential 
## scale reduction factor on split chains (at convergence, Rhat = 1).
marginal_effects(fitBrmCorrResp)

plot(fitBrmCorrResp)

fitBrmRt<-brm(rtResp~inSet*kategory+(1|session)+(1|participant)+(1|id),data = data,family =exgaussian(link = "identity", link_sigma = "log", link_beta = "log"))
## Compiling the C++ model
## Start sampling
summary(fitBrmRt)
##  Family: exgaussian 
##   Links: mu = identity; sigma = identity; beta = identity 
## Formula: rtResp ~ inSet * kategory + (1 | session) + (1 | participant) + (1 | id) 
##    Data: data (Number of observations: 180) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1; 
##          total post-warmup samples = 4000
##     ICs: LOO = NA; WAIC = NA; R2 = NA
##  
## Group-Level Effects: 
## ~id (Number of levels: 90) 
##               Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
## sd(Intercept)     0.08      0.05     0.01     0.19         11 1.13
## 
## ~participant (Number of levels: 2) 
##               Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
## sd(Intercept)     0.91      1.19     0.01     3.66          4 1.73
## 
## ~session (Number of levels: 5) 
##               Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
## sd(Intercept)     0.08      0.07     0.00     0.25        696 1.01
## 
## Population-Level Effects: 
##                          Estimate Est.Error l-95% CI u-95% CI Eff.Sample
## Intercept                    0.49      0.25    -0.05     1.11        254
## inSet1                      -0.02      0.10    -0.23     0.14         12
## kategoryFace                -0.14      0.08    -0.31     0.01        615
## kategoryLandscape            0.02      0.08    -0.16     0.17        645
## inSet1:kategoryFace         -0.00      0.15    -0.22     0.29          9
## inSet1:kategoryLandscape    -0.10      0.13    -0.32     0.16         11
##                          Rhat
## Intercept                1.03
## inSet1                   1.14
## kategoryFace             1.02
## kategoryLandscape        1.01
## inSet1:kategoryFace      1.22
## inSet1:kategoryLandscape 1.13
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
## sigma     0.09      0.04     0.01     0.16        283 1.01
## beta      0.59      0.05     0.50     0.70       4000 1.00
## 
## Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample 
## is a crude measure of effective sample size, and Rhat is the potential 
## scale reduction factor on split chains (at convergence, Rhat = 1).
marginal_effects(fitBrmRt)

plot(fitBrmRt)